<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
    <head>
        <title></title>
        <meta charset="utf-8">
        <meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
        <link rel="stylesheet" href="../css/fonts/font-awesome.min.css">
        <link rel="stylesheet" href="../css/ui-box.css">
        <link rel="stylesheet" href="../css/ui-base.css">
        <link rel="stylesheet" href="../css/ui-color.css">
        <link rel="stylesheet" href="../css/appcan.icon.css">
        <link rel="stylesheet" href="../css/appcan.control.css">
        <link rel="stylesheet" href="../css/my/style.css">
    </head>
    <body class="um-vp" ontouchstart>
        <div id="page_0" class="my-body up ub ub-ver bc-bg" tabindex="0">
            <!--header开始-->
            <div id="header" class="my-header uh bc-text-head ub bc-head">
                <!-- 返回按钮开始 -->
                <div class="nav-btn" id="nav-left">
                    <div class="fa fa-angle-left ulev2"></div>
                </div>
                <!-- 返回按钮结束 -->
                <h1 class="ut ub-f1 ulev-3 ut-s tx-c" tabindex="0">BaiduMap JS</h1>
                <div class="nav-btn" id="nav-right"></div>
            </div>
            <div id="content" class="my-content-full1" style="background: #ebebeb;"></div>
        </div>
        <script src="../js/appcan.js"></script>
        <script src="../js/appcan.control.js"></script>
        <script src="../js/appcan.listview.js"></script>
        <script src="../js/my/smb.utils.js"></script>
        <script src="../js/my/smb.request.js"></script>
        <script src="../js/my/smb.window.js"></script>
        <script src="../js/my/smb.localStorage.js"></script>
        <script src="../js/my/smb.log.js"></script>
        <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=dij09LTYqKX0IG1FUOehA45RjNlike1i&s=1"></script>
    </body>
    <script>
        var pageName = "JSLocation";
        var map = undefined;
        appcan.ready(function() {
            pageName = smb_GetLatestOpenedWindow() || pageName;
            //导航按钮返回事件
            appcan.button("#nav-left", "btn-act", function() {
                try {
                    uexLocation.closeLocation();
                } catch(e) {
                    smb_WriteLog(pageName, e, true);
                }
                smb_CloseWindow(-1);
            });
            setTimeout(function() {
                try {
                    fnCreateBaiduMap();
                    fnOpenLocation();
                } catch(e) {
                    smb_WriteLog(pageName, e, true);
                }
            }, 200);
        });

        function fnMapCenterAndZoom(map, points) {
            var view = map.getViewport(points);
            var mapZoom = view.zoom;
            var centerPoint = view.center;
            //定义一个中心点坐标
            map.centerAndZoom(centerPoint, mapZoom);
        }

        function fnOpenLocation() {
            console.log(uexLocation)
            uexLocation.onChange = function(lat, lng) {
                var currentPosition = {
                    lng : lng,
                    lat : lat
                };
                smb_WriteLog(pageName, "onChange-" + JSON.stringify(currentPosition), true);
            }
            uexLocation.openLocation("bd09", function(error) {
                if (!error) {
                    smb_MessageBoxShow("提示", "打开成功！");
                } else {
                    smb_MessageBoxShow("提示", "打开失败！")
                }
            });
        }

        function fnCreateBaiduMap() {
            map = new BMap.Map("content");
            //在百度地图容器中创建一个地图
            var point = new BMap.Point(121.476788, 31.236552);
            //定义一个中心点坐标
            map.centerAndZoom(point, 16);
            //启用地图拖拽事件，默认启用(可不写)
            map.enableDragging();
            //启用地图滚轮放大缩小
            map.enableScrollWheelZoom();
            //启用鼠标双击放大，默认启用(可不写)
            map.enableDoubleClickZoom();
            //启用键盘上下左右键移动地图
            //mapWrapper.enableKeyboard();

            //向地图中添加缩放控件
            var ctrl_nav = new BMap.NavigationControl({
                anchor : BMAP_ANCHOR_TOP_LEFT,
                type : BMAP_NAVIGATION_CONTROL_LARGE
            });
            map.addControl(ctrl_nav);
            //向地图中添加缩略图控件
            var ctrl_ove = new BMap.OverviewMapControl({
                anchor : BMAP_ANCHOR_BOTTOM_RIGHT,
                isOpen : 1
            });
            map.addControl(ctrl_ove);
            //向地图中添加比例尺控件
            var ctrl_sca = new BMap.ScaleControl({
                anchor : BMAP_ANCHOR_BOTTOM_LEFT
            });
            map.addControl(ctrl_sca);
        }

        //创建InfoWindow
        function fnCreateMapInfoWindow(markerInfo) {
            var iw = new BMap.InfoWindow("<b class='iw_poi_title' title='" + markerInfo.title + "'>" + markerInfo.title + "</b><div class='iw_poi_content'>" + markerInfo.content + "</div>");
            return iw;
        }

        //创建一个Icon
        function fnCreateMapIcon(json) {
            var icon = new BMap.Icon(json.img, new BMap.Size(json.width, json.height), {
                imageOffset : new BMap.Size(-json.left, -json.top)
            })
            return icon;
        }

        function fnConvertToBaidu(point, callback) {
            var convertor = new BMap.Convertor();
            var pointArr = [];
            pointArr.push(point);
            convertor.translate(pointArr, 3, 5, callback);
        }
    </script>
</html>